/*
 * Copyright (c) 2010-present www.walkerljl.org All Rights Reserved.
 * The software source code all copyright belongs to the author, 
 * without permission shall not be any reproduction and transmission.
 */
package org.walkerljl.commons.mail.attach;


import org.walkerljl.commons.mail.EmailAttachment;

import javax.activation.DataSource;
import javax.mail.util.ByteArrayDataSource;

/**
 * ByteArrayAttachment
 *
 * @author lijunlin
 */
public class ByteArrayAttachment extends EmailAttachment {

    protected final byte[] content;
    protected final String contentType;

    public ByteArrayAttachment(byte[] content, String contentType, String name, String contentId) {
        super(name, contentId);
        this.content = content;
        this.contentType = contentType;
    }

    /**
     * Returns <code>ByteArrayDataSource</code>.
     */
    @Override
    public DataSource getDataSource() {
        return new ByteArrayDataSource(content, contentType);
    }

    /**
     * Returns content type.
     */
    public String getContentType() {
        return contentType;
    }
}